import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "home",
    component: () => import("../components/HomeView.vue"),
  },
  {
    path: "/service",
    name: "service",
    component: () => import("../components/ServiceView.vue"),
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/user/LoginView.vue"),
  },
  {
    path: "/register",
    name: "register",
    component: () => import("../views/user/RegisterView.vue"),
  },
  {
    path: "/news",
    name: "news",
    component: () => import("../components/NewsView.vue"),
  },

  {
    path: "/living",
    name: "living",
    component: () => import("../views/living/IndexView.vue"),
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/living/phonepay",
    name: "phonepay",
    component: () => import("../views/living/PhonePayView.vue"),
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/living/pay",
    name: "livingpay",
    component: () => import("../views/living/PayView.vue"),
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/living/payrecord",
    name: "payrecord",
    component: () => import("../views/living/PayRecord.vue"),
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/living/detail/:id",
    name: "livingdetail",
    component: () => import("../views/living/NewsDetailView.vue"),
    meta: {
      isLogin: true,
    },
  },

  {
    path: "/stop",
    name: "stop",
    component: () => import("../views/stop/IndexView.vue"),
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/stop/address",
    name: "address",
    component: () => import("../views/stop/AddressListView.vue"),
    meta: {
      isLogin: true,
    },
  },

  {
    path: "/stop/record",
    name: "record",
    component: () => import("../views/stop/RecordView.vue"),
    meta: {
      isLogin: true,
    },
  },

  {
    path: "/stop/detail/:id",
    name: "detail",
    component: () => import("../views/stop/DetailView.vue"),
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/stop/buslist",
    name: "buslist",
    component: () => import("../views/stop/BusListView.vue"),
    meta: {
      isLogin: true,
    },
  },

  {
    path: "/newsdetail/:id",
    name: "newsdetail",
    component: () => import("../components/NewsDetail.vue"),
  },

  {
    path: "/mine",
    name: "mine",
    component: () => import("../components/MineView.vue"),
    meta: {
      isLogin: true,
    },
  },

  {
    path: "/mine/info",
    name: "info",
    component: () => import("../views/user/UserinfoView.vue"),
    meta: {
      isLogin: true,
    },
  },

  // 地铁 意见反馈
  {
    path: "/feedback",
    name: "feedback",
    component: () => import("../views/metro/feedback/FeedBack.vue"),
  },
  // 地铁 意见反馈详情页
  {
    path: "/feeddetail",
    name: "feeddetail",
    component: () => import("../views/metro/feedback/FeedDetail.vue"),
  },
  {
    path: "/mine/advice",
    name: "advice",
    component: () => import("../views/user/AdviceView.vue"),
    meta: {
      isLogin: true,
    },
  },
  {
    path: "/mine/order",
    name: "order",
    component: () => import("../views/user/OrderView.vue"),
    meta: {
      isLogin: true,
    },
  },
  // 地铁
  {
    path: "/metro",
    name: "metro",
    component: () => import("../views/metro/IndexView.vue"),
  },
  // 地铁 资讯
  {
    path: "/press",
    name: "press",
    component: () => import("../views/metro/press/MetroPress.vue"),
  },
  // 资讯详情页
  {
    path: "/pressdetail",
    name: "pressdetail",
    component: () => import("../views/metro/press/PressDetail.vue"),
  },
  // 地铁 乘车码
  {
    path: "/card",
    name: "card",
    component: () => import("../views/metro/card/MetroCard.vue"),
  },
  // 地铁 失物招领
  {
    path: "/found",
    name: "found",
    component: () => import("../views/metro/found/MetroFound.vue"),
  },
  // 地铁 线路站点
  {
    path: "/line",
    name: "line",
    component: () => import("../views/metro/line/MetroLine.vue"),
  },
  // 地铁 线路站点详情
  {
    path: '/linedetail',
    name: 'linedetail',
    component: () => import("../views/metro/line/LineDetail.vue")
  },
  // 地铁 公告相关
  {
    path: "/notice",
    name: "notice",
    component: () => import("../views/metro/notice/MetroNotice.vue"),
  },
  // 地铁 乘车记录
  {
    path: "/record",
    name: "record",
    component: () => import("../views/metro/record/MetroRecord.vue"),
  },
  // 地铁 公告详情页
  {
    path: "/noticedetail",
    name: "noticedetail",
    component: () => import("../views/metro/notice/NoticeDetail.vue")
  },
  // 失物招领
  {
    path: "/founddetail",
    name: "founddetail",
    component: () => import("../views/metro/found/FoundDetail.vue")
  },
  // 外卖
  {
    path: "/takeout",
    name: "takeout",
    component: () => import("../views/takeout/IndexView.vue"),
  },
  //  外卖 意见反馈
  {
    path: "/takeoutfeedback",
    name: "takeoutfeedback",
    component: () => import("../views/takeout/feedback/FeedBack.vue")
  },
  // 外卖 意见反馈详情页
  {
    path: "/takeoutfeeddetail",
    name: "takeoutfeeddetail",
    component: () => import("../views/takeout/feedback/FeedDetail.vue")
  },
  // 外卖 店家详情页
  {
    path: "/sellerdetail",
    name: "sellerdetail",
    component: () => import("../views/takeout/TakeoutDetail.vue")
  },
  //
  {
    path: "/takeoutcollect",
    name: "takeoutcollect",
    component: () => import("../views/takeout/collect/TakeoutCollect.vue")
  },

  {
    path: "/mine/reset",
    name: "reset",
    component: () => import("../views/user/ResetPwdView.vue"),
    meta: {
      isLogin: true,
    },
  },

// 找工作
{
  path: '/job',
  name: 'job',
  component: () => import('../views/job/IndexView.vue')
},
// 招聘详情页
{
  path: '/jobdetail/:id',
  name: 'jobdetail',
  component: () => import('../views/job/component/jobDetail.vue')
},
// 投递简历
{
  path:"/deliver/:companyId/:professionId/:name",
  name:"deliver", 
  component:()=>import("@/views/job/component/deliverView.vue")
},
// 投递简历列表
{
  path:"/deliverlist",
  name:"deliverlist",
  component:()=>import("@/views/job/component/deliverList.vue")
},
// 找房子
{
  path: '/house',
  name: 'house',
  component: () => import('../views/house/IndexView.vue')
},
// 房子详情页
{
  path: '/housedetail/:id',
  name: 'housedetail',
  component: () => import('../views/house/houseDetail.vue')
},

  //智慧交通
  {
    path: "/traffic",
    name: "traffic",
    component: () => import("../views/traffic/IndexView.vue"),
  },
  //绑定驾驶证
  {
    path: "/bindLicense",
    name: "bindLicense",
    component: () => import("../views/traffic/bindLicense/BindLicense.vue"),
  },
  //获取当前登录人驾驶证信息
  {
    path: "/getLicense",
    name: "getLicense",
    component: () => import("../views/traffic/getLicense/GetLicense.vue"),
  },
  //获取驾驶证详细信息
  {
    path: "/licenseDetails",
    name: "licenseDetails",
    component: () =>
      import("../views/traffic/licenseDetails/LicenseDetails.vue"),
  },
  //解除绑定驾驶证
  {
    path: "/removeLicense",
    name: "removeLicense",
    component: () => import("../views/traffic/removeLicense/RemoveLicense.vue"),
  },

  //生活管理
  {
    path: "/active",
    name: "active",
    component: () => import("../views/activity/IndexView.vue"),
  },
  // //学习
  // {
  //   path: "/study/:id",
  //   name: "study",
  //   component: () => import("../views/activity/completed/StudyDetail.vue"),
  // },

  // //生活
  // {
  //   path: "/life/:id",
  //   name: "life",
  //   component: () => import("../views/activity/completed/LifeDetail.vue"),
  // },
  // 活动详情
  {
    path: "/activedetail/:id",
    name: "activedetail",
    component: () => import("../views/activity/completed/ActiveDetail.vue"),
  },




  // 看电影
  {
    path: "/movie",
    name: "movie",
    redirect: "/movie/film",
    component: () => import("../views/movie/IndexView.vue"),
    children: [{
        path: "film",
        name: "film",
        component: () => import("../views/movie/components/FilmView.vue")
      },
      {
        path: "cinema",
        name: "cinema",
        component: () => import("../views/movie/components/FilmView.vue")
      },
    ]
  },
  {
    path: "/movie/film/detail/:id",
    name: "filmdetail",
    component: () => import("../views/movie/FilmDetailView.vue"),
  },
  {
    path: "/movie/film/comments/:id",
    name: "filmcomments",
    component: () => import("../views/movie/FilmComments.vue"),
  },


];

const router = new VueRouter({
  mode: "hash",
  base: process.env.BASE_URL,
  routes,
});
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) {
    return originalPush.call(this, location, onResolve, onReject);
  }
  return originalPush.call(this, location).catch((err) => err);
};
router.beforeEach((to, from, next) => {
  // 判断是否需要登录
  if (to.meta.isLogin) {
    let token = localStorage.getItem("token");
    if (!token) {
      next("/login");
    }
  }
  if (to.path == '/login' && from.path != "/register") {
    //保存当前路由
    localStorage.setItem("preRoute", router.currentRoute.fullPath);
    let user = localStorage.getItem("token");
    if (user) {
      next("/");
    }
  }
  document.title = to.meta.title ?? "智慧城市";
  next();
});
export default router;